This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

library(arules)
library(arulesViz)
data("Groceries")
class(Groceries)
[1] "transactions"
attr(,"package")
[1] "arules"
length(Groceries)
[1] 9835
dim(Groceries)
[1] 9835  169
itemLabels(Groceries)
  [1] "frankfurter"               "sausage"                  
  [3] "liver loaf"                "ham"                      
  [5] "meat"                      "finished products"        
  [7] "organic sausage"           "chicken"                  
  [9] "turkey"                    "pork"                     
 [11] "beef"                      "hamburger meat"           
 [13] "fish"                      "citrus fruit"             
 [15] "tropical fruit"            "pip fruit"                
 [17] "grapes"                    "berries"                  
 [19] "nuts/prunes"               "root vegetables"          
 [21] "onions"                    "herbs"                    
 [23] "other vegetables"          "packaged fruit/vegetables"
 [25] "whole milk"                "butter"                   
 [27] "curd"                      "dessert"                  
 [29] "butter milk"               "yogurt"                   
 [31] "whipped/sour cream"        "beverages"                
 [33] "UHT-milk"                  "condensed milk"           
 [35] "cream"                     "soft cheese"              
 [37] "sliced cheese"             "hard cheese"              
 [39] "cream cheese "             "processed cheese"         
 [41] "spread cheese"             "curd cheese"              
 [43] "specialty cheese"          "mayonnaise"               
 [45] "salad dressing"            "tidbits"                  
 [47] "frozen vegetables"         "frozen fruits"            
 [49] "frozen meals"              "frozen fish"              
 [51] "frozen chicken"            "ice cream"                
 [53] "frozen dessert"            "frozen potato products"   
 [55] "domestic eggs"             "rolls/buns"               
 [57] "white bread"               "brown bread"              
 [59] "pastry"                    "roll products "           
 [61] "semi-finished bread"       "zwieback"                 
 [63] "potato products"           "flour"                    
 [65] "salt"                      "rice"                     
 [67] "pasta"                     "vinegar"                  
 [69] "oil"                       "margarine"                
 [71] "specialty fat"             "sugar"                    
 [73] "artif. sweetener"          "honey"                    
 [75] "mustard"                   "ketchup"                  
 [77] "spices"                    "soups"                    
 [79] "ready soups"               "Instant food products"    
 [81] "sauces"                    "cereals"                  
 [83] "organic products"          "baking powder"            
 [85] "preservation products"     "pudding powder"           
 [87] "canned vegetables"         "canned fruit"             
 [89] "pickled vegetables"        "specialty vegetables"     
 [91] "jam"                       "sweet spreads"            
 [93] "meat spreads"              "canned fish"              
 [95] "dog food"                  "cat food"                 
 [97] "pet care"                  "baby food"                
 [99] "coffee"                    "instant coffee"           
[101] "tea"                       "cocoa drinks"             
[103] "bottled water"             "soda"                     
[105] "misc. beverages"           "fruit/vegetable juice"    
[107] "syrup"                     "bottled beer"             
[109] "canned beer"               "brandy"                   
[111] "whisky"                    "liquor"                   
[113] "rum"                       "liqueur"                  
[115] "liquor (appetizer)"        "white wine"               
[117] "red/blush wine"            "prosecco"                 
[119] "sparkling wine"            "salty snack"              
[121] "popcorn"                   "nut snack"                
[123] "snack products"            "long life bakery product" 
[125] "waffles"                   "cake bar"                 
[127] "chewing gum"               "chocolate"                
[129] "cooking chocolate"         "specialty chocolate"      
[131] "specialty bar"             "chocolate marshmallow"    
[133] "candy"                     "seasonal products"        
[135] "detergent"                 "softener"                 
[137] "decalcifier"               "dish cleaner"             
[139] "abrasive cleaner"          "cleaner"                  
[141] "toilet cleaner"            "bathroom cleaner"         
[143] "hair spray"                "dental care"              
[145] "male cosmetics"            "make up remover"          
[147] "skin care"                 "female sanitary products" 
[149] "baby cosmetics"            "soap"                     
[151] "rubbing alcohol"           "hygiene articles"         
[153] "napkins"                   "dishes"                   
[155] "cookware"                  "kitchen utensil"          
[157] "cling film/bags"           "kitchen towels"           
[159] "house keeping products"    "candles"                  
[161] "light bulbs"               "sound storage medium"     
[163] "newspapers"                "photo/film"               
[165] "pot plants"                "flower soil/fertilizer"   
[167] "flower (seeds)"            "shopping bags"            
[169] "bags"                     
summary(Groceries)
transactions as itemMatrix in sparse format with
 9835 rows (elements/itemsets/transactions) and
 169 columns (items) and a density of 0.02609146 

most frequent items:
      whole milk other vegetables       rolls/buns             soda 
            2513             1903             1809             1715 
          yogurt          (Other) 
            1372            34055 

element (itemset/transaction) length distribution:
sizes
   1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
2159 1643 1299 1005  855  645  545  438  350  246  182  117   78   77   55   46 
  17   18   19   20   21   22   23   24   26   27   28   29   32 
  29   14   14    9   11    4    6    1    1    1    1    3    1 

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  1.000   2.000   3.000   4.409   6.000  32.000 

includes extended item information - examples:
image(Groceries)

itemFrequencyPlot(Groceries,topN=10,cex.names=1)

rules <- apriori(Groceries,parameter = list(supp=0.01,conf=0.5,maxlen=10,target="rules"))
Apriori

Parameter specification:

Algorithmic control:

Absolute minimum support count: 98 

set item appearances ...[0 item(s)] done [0.00s].
set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
sorting and recoding items ... [88 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 3 4 done [0.00s].
writing ... [15 rule(s)] done [0.00s].
creating S4 object  ... done [0.00s].
summary(rules)
set of 15 rules

rule length distribution (lhs + rhs):sizes
 3 
15 

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      3       3       3       3       3       3 

summary of quality measures:
    support          confidence        coverage            lift      
 Min.   :0.01007   Min.   :0.5000   Min.   :0.01729   Min.   :1.984  
 1st Qu.:0.01174   1st Qu.:0.5151   1st Qu.:0.02089   1st Qu.:2.036  
 Median :0.01230   Median :0.5245   Median :0.02430   Median :2.203  
 Mean   :0.01316   Mean   :0.5411   Mean   :0.02454   Mean   :2.299  
 3rd Qu.:0.01403   3rd Qu.:0.5718   3rd Qu.:0.02598   3rd Qu.:2.432  
 Max.   :0.02227   Max.   :0.5862   Max.   :0.04342   Max.   :3.030  
     count      
 Min.   : 99.0  
 1st Qu.:115.5  
 Median :121.0  
 Mean   :129.4  
 3rd Qu.:138.0  
 Max.   :219.0  

mining info:
inspect(rules)
soda_rules_rhs <- apriori(Groceries,parameter=list(supp=0.01,conf=0.5,maxlen=10,minlen=2),
                  appearance=list(default="lhs",rhs="soda"))
Apriori

Parameter specification:

Algorithmic control:

Absolute minimum support count: 98 

set item appearances ...[1 item(s)] done [0.00s].
set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
sorting and recoding items ... [88 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 3 4 done [0.00s].
writing ... [0 rule(s)] done [0.00s].
creating S4 object  ... done [0.00s].
inspect(soda_rules_rhs)
soda_rules_lhs <- apriori(Groceries,parameter=list(supp=0.01,conf=0.5,maxlen=10,minlen=2),
                  appearance=list(default="rhs",lhs="soda"))
Apriori

Parameter specification:

Algorithmic control:

Absolute minimum support count: 98 

set item appearances ...[1 item(s)] done [0.00s].
set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
sorting and recoding items ... [88 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 done [0.00s].
writing ... [0 rule(s)] done [0.00s].
creating S4 object  ... done [0.00s].
inspect(soda_rules_lhs)
plot(rules)

plot(rules,engine="plotly")
subrules <- head(rules,n=10,by="confidence")
plot(subrules,method="graph",engine="htmlwidget")
plot(subrules,method="paracoord")

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.

LS0tDQp0aXRsZTogIlIgTm90ZWJvb2siDQpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sNCi0tLQ0KDQpUaGlzIGlzIGFuIFtSIE1hcmtkb3duXShodHRwOi8vcm1hcmtkb3duLnJzdHVkaW8uY29tKSBOb3RlYm9vay4gV2hlbiB5b3UgZXhlY3V0ZSBjb2RlIHdpdGhpbiB0aGUgbm90ZWJvb2ssIHRoZSByZXN1bHRzIGFwcGVhciBiZW5lYXRoIHRoZSBjb2RlLiANCg0KVHJ5IGV4ZWN1dGluZyB0aG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